package com.lehecai.core.api.openapi;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;

/**
 * 二维码
 * @author He Wang
 *
 */
public class QrCode extends AbstractApiResultBean {
	
	public static final String QUERY_QR_ID = "qr_id";
	
	public static final String SET_QR_NAME = "qr_name";
	public static final String SET_QR_IPHONE_URL = "qr_ios_url";
	public static final String SET_QR_IPHONE_VERSION = "ios_qrcode_version";
	public static final String SET_QR_ANDROID_URL = "qr_android_url";
	public static final String SET_QR_ANDROID_VERSION = "android_qrcode_version";
	public static final String SET_QR_IPAD_URL = "qr_ipad_url";
	public static final String SET_QR_IPAD_VERSION = "ipad_qrcode_version";
	public static final String SET_QR_WAP_URL = "qr_wap_url";
	public static final String SET_QR_WAP_VERSION = "wap_qrcode_version";
	public static final String SET_QR_URL = "url";
	public static final String SET_QR_REMARK = "remarks";
	
	public static final String ORDER_TIME_ADD = "qr_create_time";
	public static final String ORDER_TIME_UPDATE = "qr_update_time";
	
	private Long id;					       //二维码编号
	private String name;				       //二维码名称
	private String iphoneUrl;			       //iphone下载地址
	private String iphoneVersion;              //iphone版本
	private String androidUrl;			       //android下载地址
	private String androidVersion;             //android版本
	private String ipadUrl;			           //ipad下载地址
	private String ipadVersion;                //ipad版本
	private String wapUrl;			           //wap下载地址
	private String wapVersion;                 //wap版本
	private String url;                        //下载地址
	private String remark;                     //备注
	
	private Date createTime;				       
	private Date updateTime;			            
	
	public static QrCode convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		QrCode qrCode = new QrCode();
		qrCode.setId(getLong(object, QUERY_QR_ID));
		qrCode.setName(getString(object, SET_QR_NAME));
		qrCode.setIphoneUrl(getString(object, SET_QR_IPHONE_URL));
		qrCode.setIphoneVersion(getString(object, SET_QR_IPHONE_VERSION));
		qrCode.setAndroidUrl(getString(object, SET_QR_ANDROID_URL));
		qrCode.setAndroidVersion(getString(object, SET_QR_ANDROID_VERSION));
		qrCode.setIpadUrl(getString(object, SET_QR_IPAD_URL));
		qrCode.setIpadVersion(getString(object, SET_QR_IPAD_VERSION));
		qrCode.setWapUrl(getString(object, SET_QR_WAP_URL));
		qrCode.setWapVersion(getString(object, SET_QR_WAP_VERSION));
		qrCode.setUrl(getString(object, SET_QR_URL));
		qrCode.setCreateTime(CoreDateUtils.parseDate(getString(object, ORDER_TIME_ADD), CoreDateUtils.DATETIME));
		qrCode.setUpdateTime(CoreDateUtils.parseDate(getString(object, ORDER_TIME_UPDATE), CoreDateUtils.DATETIME));
		qrCode.setRemark(getString(object, SET_QR_REMARK));
		return qrCode;
	}
	
	public static List<QrCode> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<QrCode> list = new ArrayList<QrCode>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}


	public String getIphoneUrl() {
		return iphoneUrl;
	}

	public void setIphoneUrl(String iphoneUrl) {
		this.iphoneUrl = iphoneUrl;
	}

	public String getIphoneVersion() {
		return iphoneVersion;
	}

	public void setIphoneVersion(String iphoneVersion) {
		this.iphoneVersion = iphoneVersion;
	}

	public String getAndroidUrl() {
		return androidUrl;
	}

	public void setAndroidUrl(String androidUrl) {
		this.androidUrl = androidUrl;
	}

	public String getAndroidVersion() {
		return androidVersion;
	}

	public void setAndroidVersion(String androidVersion) {
		this.androidVersion = androidVersion;
	}

	public String getIpadUrl() {
		return ipadUrl;
	}

	public void setIpadUrl(String ipadUrl) {
		this.ipadUrl = ipadUrl;
	}

	public String getIpadVersion() {
		return ipadVersion;
	}

	public void setIpadVersion(String ipadVersion) {
		this.ipadVersion = ipadVersion;
	}

	public String getWapUrl() {
		return wapUrl;
	}

	public void setWapUrl(String wapUrl) {
		this.wapUrl = wapUrl;
	}

	public String getWapVersion() {
		return wapVersion;
	}

	public void setWapVersion(String wapVersion) {
		this.wapVersion = wapVersion;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRemark() {
		return remark;
	}

}
